package se.cbb.scripts;

import java.io.File;
import java.util.ArrayList;

import se.cbb.misc.SequenceFileWriter;

public class DeterminePosteriorOfMultipleMCMC {

	public static void main(String[] args) {
		try{ 
			String path = "/Users/rhali/Movies/Projects/VMCMC/simRuns/simRun2/";
			String path1 = path + "GeneTrees/";
			File folder = new File(path1);
			File[] listOfFiles = folder.listFiles();
			int numberofFiles = listOfFiles.length;
			ArrayList<String> list = new ArrayList<String>();
			
			for(int i = 0; i < numberofFiles; i++) {
				if(listOfFiles[i].getName().endsWith(".nwk")) {
					System.out.println("I was here");
					list.add(listOfFiles[i].getName().substring(0, listOfFiles[i].getName().length()-4));
				}
			}
			String fileName = "PosteriorScript.sh";
			
			//java -jar VMCMC-1.0.0-uber.jar -p GeneTree1Informed.mcmc -b 0
			SequenceFileWriter.writeAndAppendLine(path, fileName, "#!/bin/bash");
			for(int i = 0; i < list.size(); i++) {
				SequenceFileWriter.writeAndAppendLine(path, fileName, "java -jar VMCMC-1.0.0-uber.jar -p " + list.get(i) + ".mcmc" + " -b 0 -o " + list.get(i) + ".pos");
			}			
		} catch (Exception e) {
			System.out.println("Error: " + e.getMessage());
		}

	}

}
